

exp3 <- read_csv("Data/Conjoint - Statecraft_competence - 3_April 22, 2021_22.csv")


names(exp3)[1] <- "UK_fav"
names(exp3)[2] <- "Canada_fav"
names(exp3)[3] <- "India_fav"
names(exp3)[4] <- "China_fav"
names(exp3)[5] <- "Egypt_fav"
names(exp3)[6] <- "SoAf_fav"
names(exp3)[7] <- "Russia_fav"
names(exp3)[8] <- "NoKor_fav"
names(exp3)[9] <- "Argentina_fav"
names(exp3)[10] <- "Pakistan_fav"
names(exp3)[11] <- "Iran_fav"
names(exp3)[12] <- "Syria_fav"
names(exp3)[13] <- "Cuba_fav"
names(exp3)[14] <- "Sudan_fav"
names(exp3)[15] <- "Mexico_fav"
names(exp3)[16] <- "Colombia_fav"
names(exp3)[17] <- "Myanmar_fav"
names(exp3)[18] <- "Afghanistan_fav"
names(exp3)[19] <- "Morocco_fav"


exp3 <- exp3 %>%
  mutate(party = ifelse(Q52 == "Neither", "TrueInd", 
                        ifelse(Q52 == "Lean Republican", "IndRep",
                               ifelse(Q52 == "Lean Democrat", "IndDem", NA))))
         
exp3$party[exp3$Q50 == "Not very strong"] <- "WeakRep"
exp3$party[exp3$Q50 == "Very strong"] <- "StrongRep"
exp3$party[exp3$Q48 == "Not very strong"] <- "WeakDem"
exp3$party[exp3$Q48 == "Very strong"] <- "StrongDem"

exp3$Q50 <- exp3$Q52 <- exp3$Q48 <- exp3$Q46 <- NULL


exp3 <- exp3 %>%
  rename(urban_rural = Q118)

exp3 <- exp3 %>%
  rename(support_narc = '1_Q181_4',
         support_dem = '1_Q147_4',
         USint_narc = '1_Q181_5',
         USint_dem = '1_Q147_5',
         costly_narc = '1_Q181_6',
         costly_dem = '1_Q147_6',
         effective_narc = '1_Q181_7',
         effective_dem = '1_Q147_10',
         strength_narc = '1_Q181_10',
         stength_dem = '1_Q147_11',
         message_narc = '1_Q181_11',
         message_dem = '1_Q147_12')
                                                    
exp3 <- exp3 %>%
  mutate(DV_support = ifelse(badbehavior1 == "drugs", support_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", support_dem, NA)),
         DV_interests = ifelse(badbehavior1 == "drugs", USint_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", USint_dem, NA)),
         DV_costly = ifelse(badbehavior1 == "drugs", costly_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", costly_dem, NA)),
         DV_effective = ifelse(badbehavior1 == "drugs", effective_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", effective_dem, NA)),
         DV_strength = ifelse(badbehavior1 == "drugs", strength_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", stength_dem, NA)),
         DV_message = ifelse(badbehavior1 == "drugs", message_narc, 
                             ifelse(badbehavior1 == "stopdemocracy", message_dem, NA))
         )

# Final DVs
exp3 <- exp3 %>%
  mutate(
DV_support = as.numeric(DV_support),
DV_interests = as.numeric(DV_interests),
DV_costly = as.numeric(DV_costly),
DV_effective = as.numeric(DV_effective),
DV_strength = as.numeric(DV_strength),
DV_message = as.numeric(DV_message)
  )

exp3 <- exp3 %>%
  select(-support_narc, -support_dem, -USint_narc, -USint_dem, -costly_narc,
         -costly_dem, -effective_narc, -effective_dem, -strength_narc,
         -stength_dem, -message_narc, -message_dem)


exp3 <- exp3 %>%
  mutate(
    Effect = ifelse(c1_attrib1_name == "Effect on economy", word(c1_attrib1, 1), 
                    ifelse(c1_attrib2_name == "Effect on economy", word(c1_attrib2, 1),
                           ifelse(c1_attrib3_name == "Effect on economy", word(c1_attrib3, 1),
                                  ifelse(c1_attrib4_name == "Effect on economy", word(c1_attrib4, 1), NA
                    )))),
    Effect = as.numeric(str_remove(Effect, "[$]"))
  )

exp3 <- exp3 %>%
  mutate(
    Inaction = ifelse(c1_attrib1_name == "Outcome of Inaction", word(c1_attrib1, -1), 
                    ifelse(c1_attrib2_name == "Outcome of Inaction", word(c1_attrib2, -1),
                         ifelse(c1_attrib3_name == "Outcome of Inaction", word(c1_attrib3, -1),
                                ifelse(c1_attrib4_name == "Outcome of Inaction", word(c1_attrib4, -1), NA
                    )))),
  Inaction = ifelse(Inaction == "continue", "Continue", 
                    ifelse(Inaction == "future", "TickingClock", NA))
)


exp3 <- exp3 %>%
  mutate( 
    Rationale = ifelse(c1_attrib1_name == "US Rationale for Proposal", word(c1_attrib1, -1),
                       ifelse(c1_attrib2_name == "US Rationale for Proposal", word(c1_attrib2, -1),
                              ifelse(c1_attrib3_name == "US Rationale for Proposal", word(c1_attrib3, -1),
                                     ifelse(c1_attrib4_name == "US Rationale for Proposal", word(c1_attrib4, -1), NA
                    )))),
    Rationale = ifelse(Rationale == "time" | Rationale == "legislation", "LongRun", 
                       ifelse(Rationale == "activists" | Rationale == "traffickers", "Immediate", NA))
  )



exp3 <- exp3 %>%
  mutate( 
    Author = ifelse(c1_attrib1_name == "Proposal Author", word(c1_attrib1, -1),
                       ifelse(c1_attrib2_name == "Proposal Author", word(c1_attrib2, -1),
                              ifelse(c1_attrib3_name == "Proposal Author", word(c1_attrib3, -1),
                                     ifelse(c1_attrib4_name == "Proposal Author", word(c1_attrib4, -1), NA
                                     )))),
    Author = ifelse(Author == "appointee", "Appointee_only",
                    ifelse(Author == "donor", "Appointee_donor",
                           ifelse(Author == "service", "Professional",
                                  ifelse(Author == "Afghanistan" | Author == "Colombia" | Author == "Mexico" | Author == "Morocco" | Author == "Myanmar", "Professional_expert", NA
                                     ))))
  )


exp3 <- exp3 %>%
  select(-c1_attrib1_name, -c1_attrib2_name, -c1_attrib3_name, -c1_attrib4_name, 
         -c1_attrib1, -c1_attrib2, -c1_attrib3, -c1_attrib4)



exp3 <- exp3 %>%
  mutate(Background = ifelse(countrybackground == "has a long history of repressing pro-democracy activists" | 
                               countrybackground == "has a long history of ignoring drug trafficking across its borders", "LongHistory",
                             ifelse(countrybackground == "recently shifted policy, leading to a surge in drug trafficking across its borders" |
                                      countrybackground == "recently shifted policy, leading to a surge in repression of pro-democracy activists", "RecentShift", NA)))


# Code policy types
exp3 <- exp3 %>%
  mutate( 
     Policy = ifelse(policy == "Financial sanctions prohibiting certain international payments to and from", "Sanctions", 
                     ifelse(policy == "Financial inducements facilitating investment in", "Inducements", NA))
  )


exp3 <- exp3 %>%
  select(-policy, -policy2, -policy3, -countrybackground, -outcome, -number)



# Code prior support
exp3 <- exp3 %>%
  mutate(
    Prior = ifelse(country1 == "Afghanistan", Afghanistan_fav, 
                   ifelse(country1 == "Colombia", Colombia_fav,
                          ifelse(country1 == "Mexico", Mexico_fav, 
                                 ifelse(country1 == "Morocco", Morocco_fav, 
                                        ifelse(country1 == "Myanmar", Myanmar_fav, NA)))))
  )


# Delete unneeded rows
exp3 = exp3[-c(1, 2),]


